/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MVC;

/**
 *
 * @author Prashanna
 */
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.event.*;

class MVC extends JFrame {

	private Container c;
	private JMenuBar menubar;
	private JMenu spieler;
	public JFrame dialog = new JFrame("Dialog");
	private JPanel panel;
	private JLabel lblname;
	private JLabel lblvorname;
	public JTextField txtname;
	public JTextField txtvorname;
	public JButton btnOK = new JButton("Ok");

	private static GridBagLayout gbl;

	final static int f_size = 11;
	final static int f_weigth = 320;
	final static int f_height = 220;

	// GUI Initialisiert
	public JTextField spieler1 = new JTextField();

	private Border loweredetched = BorderFactory
			.createEtchedBorder(EtchedBorder.LOWERED);

	public MVC() {
		super("Tenisszähler");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		//setSize(f_weigth, f_height);

		c = this.getContentPane();
		gbl = new GridBagLayout();
		c.setLayout(gbl);

		// Menu x, y, width, height, double weightx, double weighty
		c.add(Menue(), new GridBagConstraints(0, 0, 1, 1, 1, 0.15,
				GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0,
						0, 0, 0), 0, 0));
		// Status
		c.add(Spieler(), new GridBagConstraints(0, 1, 1, 1, 1, 1,
				GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0,
						0, 0, 0), 0, 0));
		// Punktestand

		Dialog();
		
		pack();
		setVisible(true);
	}

	// JMenu
	public JMenuBar Menue() {
		menubar = new JMenuBar();
		spieler = new JMenu("Spieler");
		menubar.add(spieler);

		return menubar;
	}

	public void setText(String str) {
		this.spieler1.setText(str);
	}

	// OK Spieler
	public JButton OK() {
		return this.btnOK;
	}

	public void DialogVisible(boolean status) {
		this.dialog.setVisible(status);
	}

	public JFrame Dialog() {
		// dialog = new JFrame("Dialog");
		//this.dialog.setSize(500, 500);
		// frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		panel = new JPanel();
		panel.setLayout(new GridBagLayout());

		lblname = new JLabel("Name: ");
		lblname.setBorder(loweredetched);
		lblvorname = new JLabel("Vorname: ");
		lblvorname.setBorder(loweredetched);
		txtname = new JTextField();
		txtvorname = new JTextField();

		panel.add(lblname, new GridBagConstraints(0, 1, 1, 1, 1, 1,
				GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0,
						0, 0, 0), 0, 0));
		panel.add(lblvorname, new GridBagConstraints(0, 2, 1, 1, 1, 1,
				GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0,
						0, 0, 0), 0, 0));
		panel.add(txtname, new GridBagConstraints(1, 1, 2, 1, 1, 1,
				GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0,
						0, 0, 0), 0, 0));
		panel.add(txtvorname, new GridBagConstraints(1, 2, 2, 1, 1, 1,
				GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0,
						0, 0, 0), 0, 0));
		panel.add(OK(), new GridBagConstraints(1, 3, 1, 1, 1, 1,
				GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0,
						0, 0, 0), 0, 0));

		dialog.getContentPane().add(panel);

		this.dialog.pack();
				
		return dialog;
	}

	// Name von Spielern
	public JPanel Spieler() {
		panel = new JPanel();
		panel.setBorder(loweredetched);
		gbl = new GridBagLayout();
		panel.setLayout(gbl);

		spieler1.setEditable(false);

		// Spieler1
		panel.add(spieler1, new GridBagConstraints(0, 1, 1, 1, 1, 0.1,
				GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(
						80, 50, 40, 30), 0, 0));
		return panel;
	}

	// Main
	public static void main(String[] args) {
		MVC view = new MVC();
		new MVCController(view);
	}

	void addtest(ActionListener al) {
		this.btnOK.addActionListener(al);

	}

	void addSpieler(AbstractAction ac) {
		spieler.add(ac);
	}

}